Release 10.1A: OpenEdge Development:
Progress 4GL Handbook
Super procedure example
To show some of the principles of super procedures in action, you can create one that manipulates windows in a simple way. The super procedure needs to have a single entry point, an internal procedure called
alignWindow, to position all windows to the same column.
![]()
To create an example super procedure:
- From the AppBuilder, select New
Structured Procedure.
- Make sure the Procedures toggle box is checked so that this nonvisual program template is in the list.
- Add a new procedure called
alignWindow:
The
TARGET-PROCEDUREhandle is the handle of the window procedure that this is a super procedure for. The code simply sets its current window’s column position to 20. Note the use of chained attribute references. You can chain together as many object attributes as you need in a single expression, as long as all the attributes (except the last) evaluate to handles. Also, theCOLattribute is of typeDECIMAL, so don’t forget the decimal on the value20.0.Structured procedures don’t have any visualization, so there’s no real design window for them in the AppBuilder. Instead, you get a window with a tree view with all the code sections.
- Expand the tree view and double-click on any section to bring it up in the Section Editor:
![]()
Now you need a standard procedure that knows how to start a super procedure. It needs to determine whether it’s already running, run it if it’s not there, and then make it a super procedure of the requesting procedure.
- Define a new external procedure called
h-StartSuper.pwith this code:
This code looks for a running instance of the procedure name passed in, using the
SESSIONprocedure list. If it’s not there, it runs it. Then it adds it as a super procedure of theSOURCE-PROCEDURE, which is the procedure that ranh-StartSuper.p.- Add statements to the main block of both
h-CustOrderWin6.wandh-OrderWin.wto geth-StartSuper.pto starth-WinSuper.pand then to runalignWindow:
To review what’s happening when you run
h-CustOrderWin6.wagain, look at the diagram in Figure 14–7.Figure 14–7: Running the sample procedure with a super procedure
![]()
The dotted lines represent transient relationships that are only present during startup. Both
h-CustOrderWin6.wandh-OrderWin.wrunh-StartSuper.pto get their super procedure. When each runs it in turn,SOURCE-PROCEDUREpoints back to the procedure that ran it.h-StartSuper.pestablishesh-WinSuper.pas the super procedure for each one in turn, and then goes away because it was not run persistent itself. It was only needed to set up the relationships.Once the persistent procedures are all set up, each one runs
alignWindow. There’s noalignWindowprocedure in either of the.w’s, so Progress searches the super procedure stack and locates it inh-WinSuper.pand runs that code. NowalignWindowcan refer toTARGET-PROCEDUREto access the window handle inside each of the.w’s.
![]()
To add another small layer of complexity:
Figure 14–8: Variation on running the sample procedures with a super procedure
- Add an implementation of
alignWindowinh-CustOrderWin6.w:
This code uses a
RUN SUPERto invoke the standard behavior inh-WinSuper.p, and then adds some more code of its own, in this case to set theROWattribute of the window.So the net effect of these two versions of
alignWindowis to set both theCOLand theROW.- Do the same thing in
h-OrderWin.w. Define a version ofalignWindowthat setsROWto something different from the local code inh-CustOrderWin6.w:
Now all Order windows come up initially in the same place, on top of one another. You can drag them around to see all of them. The diagram in Figure 14–8 represents this second situation.
![]()
When Progress executes the
RUNalignWindowstatement, it finds the internal procedure locally and executes it. The local version first invokes the standard behavior in the super procedure and then extends it with its own custom code.Super procedures might seem like a complicated mechanism, but consider that they are intended to allow you to provide standard behavior for many procedure objects. This means that you can carefully craft the super procedure code for a type of behavior, and then every other procedure that uses that super procedure inherits the behavior automatically and transparently. This is the power of super procedures.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |